package com.lagou.comsumer7777.controller;

import com.lagou.api.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ComsumerController {

    @Reference(loadbalance = "roundrobin")
    private UserService userService;

    @RequestMapping("/dubbo")
    public String testDubbo(HttpServletRequest request) {
        String remoteAddr = request.getRemoteAddr();
        System.out.println(remoteAddr);
        RpcContext.getContext().setAttachment("visit_ip", remoteAddr);
        return userService.sayHello("dubbo");
    }
}
